<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title><?php echo $title;?></title>
    <!-- 设置缩放 -->
    <meta name="viewport" content="minimal-ui,width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
    <!-- IOS中禁用将数字识别为电话号码/忽略Android平台中对邮箱地址的识别 -->
    <meta name="format-detection" content="telephone=no" />
    <!-- windows phone 点击无高光 -->
    <meta name="msapplication-tap-highlight" content="no" />
    <!-- icon -->
    <link rel="shortcut icon" href="<?php echo ADMIN_ICO_PIC;?>" type="image/x-icon" />
    <!-- css -->
    <link rel="stylesheet" type="text/css" href="<?php echo SYS_LINK;?>admin/css/login.css?v=<?php echo V_CSSJS;?>" />

    <style>
        .login{height:auto;margin-top:-300px;padding: 40px 40px 40px 40px;}
        .login input{height:30px;margin-bottom: 5px;font-size:14px;}
        .login img{margin-bottom: 0;}
        .webtitle{color:#fff;text-decoration:none;}
        #vercodeimg{height:29px;}
        <?php
        if(isset($loginPic) && $loginPic){
            echo '.login_body {background: #333844 url('.$loginPic.') repeat center;background-size: cover;background-attachment: fixed;height: 100%;overflow: hidden;}';
        }
        ?>
        .in_select{width:239px;border:1px solid #DCDEE0;height:30px;border-radius:3px;color:#555555;margin-bottom: 5px;padding-left: 10px;}
        .sub_btn {font-size:14px;padding: 6px 8px;background: #00BCD4;color: #fff;margin-top: 5px;border:none;margin-right: 8px;}
        #restore_btn{margin-right: 0px;}
        #db_set,#db_file,#set_btn,#download_btn,#restore_btn,#public_btn{display: none;}
    </style>
</head>
<body class="login_body">

<?php
$dbConf = isset($dbConf) ? $dbConf : array();
$db_host = isset($dbConf['db_host']) ? $dbConf['db_host'] : '';
$db_user = isset($dbConf['db_user']) ? $dbConf['db_user'] : '';
$db_pwd = isset($dbConf['db_pwd']) ? $dbConf['db_pwd'] : '';
$db_name = isset($dbConf['db_name']) ? $dbConf['db_name'] : '';
$dbFiles = isset($dbFile) ? $dbFile : array();
$optionItem = '';
foreach($dbFiles as $v){
    $optionItem .= '<option value="'.$v.'">'.$v.'</option>';
}
$manageKey = isset($manageKey) && $manageKey == SYS_DEV_LOGIN_FLAG ? $manageKey : '';
?>
<div class="login">
    <div class="message"><font color="#e54ca1">ZHLCMS数据安装</font></div>
    <div id="darkbannerwrap"></div>

    <form id="hide_form" action="<?php echo SYS_URL_PATH('admin_install_setinfo');?>" method="post" onsubmit="return chkmanagelog(this)">
        <input name="manage_user" id="manage_user" placeholder="开发者帐号" required="" type="text" class="login_input" maxlength="20">
        <input name="manage_pwd" id="manage_pwd" placeholder="开发者密码" required="" type="password" class="login_input" maxlength="20">
        <input name="manage_key" id="manage_key" placeholder="开发者密钥" required="" value="<?php echo $manageKey;?>" type="password" class="login_input" maxlength="20">
        <?php if(isset($verifyFlag) && $verifyFlag == 1){?>
        <input name="manage_code" id="manage_code" placeholder="图形验证码" required="" type="text" class="login_input code"><img src="" id="vercodeimg" />
        <?php } ?>
        <select id="manage_type" class="in_select" name="manage_type" >
            <option value="0">请选择操作类型</option>
            <option value="3">1、sql文件下载</option>
            <option value="1">2、设置Mysql配置</option>
            <option value="2">3、sql文件导入</option>
            <option value="4">4、初始化CMS</option>
        </select>
        <span id="db_set">
            <input name="db_host" id="db_host" placeholder="MySql主机链接" value="<?php echo $db_host;?>" required="" type="text" class="login_input" >
            <input name="db_user" id="db_user" placeholder="MySql用户帐号" value="<?php echo $db_user;?>" required="" type="text" class="login_input" >
            <input name="db_pwd" id="db_pwd" placeholder="MySql用户密码" value="<?php echo $db_pwd;?>" required="" type="password" class="login_input" >
            <input name="db_name" id="db_name" placeholder="MySql数据库名" value="<?php echo $db_name;?>" required="" type="text" class="login_input" >
        </span>
        <select id="db_file" class="in_select" name="filedb" >
            <option value="">请选择要导入的数据sql文件</option>
            <?php echo $optionItem;?>
        </select>
        <br><br>
        <input type="button" value="更新配置" class="sub_btn" id="set_btn">
        <input type="button" value="本地下载" class="sub_btn" id="download_btn">
        <input type="button" value="数据导入" class="sub_btn" id="restore_btn">
        <input type="button" value="提交确认" class="sub_btn" id="public_btn">
    </form>

</div>

<div class="copyright"><a href="" class="webtitle">zhladmin后台</a>&nbsp;&nbsp;2022 © COPYRIGHT</div>

</body>
<script type="text/javascript" src="<?php echo SYS_LINK;?>admin/js/jquery.min.js?v=<?php echo V_CSSJS;?>"></script>
<script type="text/javascript" src="<?php echo SYS_LINK;?>plug/layer3.1.1/layer.js?v=<?php echo V_CSSJS;?>"></script>
<script language="javascript">
    var http_path = '<?php echo SYS_HOST;?>';
    var url_fix = '<?php echo SYS_URL_FIX;?>';

    function chkmanagelog(frm){
        if(!frm.manage_user.value){
            layer.msg("请输入开发者帐号！");
            frm.manage_user.focus();
            return false;
        }else if(!frm.manage_pwd.value){
            layer.msg("请输入开发者密码！");
            frm.manage_pwd.focus();
            return false;
        }else if(!frm.manage_key.value) {
            layer.msg("请输入开发者密钥！");
            frm.manage_key.focus();
            return false;

            <?php if(isset($verifyFlag) && $verifyFlag == 1){?>
        }else if(!frm.manage_code.value) {
            layer.msg("请输入图形验证码！");
            frm.manage_code.focus();
            return false;
            <?php } ?>
        }
        return true;
    }

    // 切换验证码
    $('#vercodeimg').click(function(){
        let randomNo = Math.floor(Math.random()*100+1);
        $('#vercodeimg').attr('src', http_path+'c_captcha_img/n/a_img_code/rr/'+randomNo+url_fix);
    });
    $('#vercodeimg').trigger('click');

    // 数据库文件下载
    $('#download_btn').on('click',function(){
        var filedb = $('#db_file').val();
        let checkRes = chkmanagelog(document.getElementById("hide_form"));
        if(!checkRes){

        }else if(!filedb){
            layer.msg('请选择要下载的sql文件');return false;
        }else{
            window.open("<?php echo SYS_HOST.str_replace(SYS_PATH, '', SYS_DB_PATH);?>"+filedb);
        }
    })

    // 数据库导入
    $('#restore_btn').on('click',function(){
        let checkRes = chkmanagelog(document.getElementById("hide_form"));
        var filedb = $('#db_file').val();
        if(!checkRes){

        }else if(filedb != '' && filedb != null){
            $('#manage_type').val(2);
            $('#hide_form').submit();
        }else{
            layer.msg('请选择要还原的sql文件');
        }
    })

    // 更新配置
    $('#set_btn').on('click',function(){
        let checkRes = chkmanagelog(document.getElementById("hide_form"));
        var db_host = $('#db_host').val();
        var db_user = $('#db_user').val();
        var db_pwd = $('#db_pwd').val();
        var db_name = $('#db_name').val();
        if(!checkRes){

        }else if(!db_host){
            layer.msg('MySql主机链接不能为空');
            document.getElementById("db_host").focus();
        }else if(!db_user){
            layer.msg('MySql用户帐号不能为空');
            document.getElementById("db_user").focus();
        }else if(!db_pwd){
            layer.msg('MySql用户密码不能为空');
            document.getElementById("db_pwd").focus();
        }else if(!db_name){
            layer.msg('MySql数据库名不能为空');
            document.getElementById("db_name").focus();
        }else{
            $('#manage_type').val(1);
            $('#hide_form').submit();
        }
    })

    // 类型控制
    $('#manage_type').change(function(){
        let type = $(this).val();
        $('#db_set').hide();
        $('#db_file').hide();
        $('#set_btn').hide();
        $('#download_btn').hide();
        $('#restore_btn').hide();
        $('#public_btn').hide();
        if(type == 1){
            $('#db_set').show();
            $('#set_btn').show();
        }else if(type == 2){
            $('#db_file').show();
            $('#restore_btn').show();
        }else if(type == 3){
            $('#db_file').show();
            $('#download_btn').show();
        }else if(type == 4){
            $('#public_btn').show();
        }else{
            $('#db_set').hide();
            $('#db_file').hide();
            $('#set_btn').hide();
            $('#download_btn').hide();
            $('#restore_btn').hide();
        }
    })

    // 公共确认提交
    $('#public_btn').on('click',function(){
        var manage_type = $('#manage_type').val();
        if(!manage_type){
            layer.msg('操作类型不能为空');
            document.getElementById("manage_type").focus();
        }else{
            $('#manage_type').val(manage_type);
            $('#hide_form').submit();
        }
    })

</script>
</html>